/**
 * @param {number} dividend
 * @param {number} divisor
 * @return {number}
 */
var divide = function(dividend, divisor) {
    let flag = 1
    if (divisor < 0) {
        divisor = -divisor
        flag = -flag
    }
    if (dividend < 0) {
        dividend = -dividend
        flag = -flag
    }

    if (dividend < divisor) return 0
    let result = 0,
        remain = 0

    dividend = dividend + ''


    // 按位求结果每位的值
    for (let i = 0; i < dividend.length; i++) {
        let item = dividend[i] - remain * 10 * -1;
        let l = 0
        while (item >= divisor) {
            item = item - divisor
            l++
        }
        remain = item
        if (result !== 0 || l !== 0) {
            result = result * 10 + l
        }
    }

    result = result * flag

    if (result > -(1 << 31) - 1) {
        return -(1 << 31) - 1
    }
    if (result < 1 << 31) {
        return 1 << 31
    }

    return result
};